<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>打开持久的 Internet 或 Unix 套接字连接</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.openlog.html">« openlog</a></li>
      <li style="float: right;"><a href="function.setcookie.html">setcookie »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.network.html">网络 函数</a></li>
    <li>打开持久的 Internet 或 Unix 套接字连接</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.pfsockopen" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pfsockopen</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pfsockopen</span> &mdash; <span class="dc-title">打开持久的 Internet 或 Unix 套接字连接</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.pfsockopen-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pfsockopen</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$hostname</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$error_code</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$error_message</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">float</span><span class="type"></span></span> <code class="parameter">$timeout</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>): <span class="type"><span class="type">resource</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   这个函数的作用与 <span class="function"><a href="function.fsockopen.html" class="function">fsockopen()</a></span>
   完全一样，不同的地方在于当在脚本执行完后，连接一直不会关闭。可以说它是
   <span class="function"><a href="function.fsockopen.html" class="function">fsockopen()</a></span> 的长连接版本。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pfsockopen-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   对于其参数的信息，请参考 <span class="function"><a href="function.fsockopen.html" class="function">fsockopen()</a></span> 的文档。
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pfsockopen-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>pfsockopen()</strong></span> 返回文件指针，可以跟其他文件函数（比如
   <span class="function"><a href="function.fgets.html" class="function">fgets()</a></span>、<span class="function"><a href="function.fgetss.html" class="function">fgetss()</a></span>、<span class="function"><a href="function.fwrite.html" class="function">fwrite()</a></span>、<span class="function"><a href="function.fclose.html" class="function">fclose()</a></span>
   和 <span class="function"><a href="function.feof.html" class="function">feof()</a></span>）一起使用， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pfsockopen-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">timeout</code> 现在可以为 null。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.pfsockopen-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.fsockopen.html" class="function" rel="rdfs-seeAlso">fsockopen()</a> - 打开 Internet 或者 Unix 套接字连接</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>